package org.sample.springboot.web;

import java.util.Date;

import org.sample.springboot.service.DateTimeService;
import org.sample.springbootcommon.model.DateTimeRequest;
import org.sample.springbootcommon.model.DateTimeResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@EnableAutoConfiguration
@RequestMapping("/mock")
public class DateTimeController {

	private static final Logger LOGGER = LoggerFactory.getLogger(DateTimeController.class);

	@Autowired
	private DateTimeService dateTimeService;

	@RequestMapping(method = RequestMethod.GET, path = "/datetime")
	public DateTimeResponse getDateTime() {

		DateTimeResponse response = new DateTimeResponse();
		response.setStart(new Date().toString());
		response.setEnd(dateTimeService.getDateTime());

		return response;
	}

	@RequestMapping(method = RequestMethod.POST, path = "/datetime")
	public DateTimeResponse getDateTimeWithId(@RequestBody DateTimeRequest request) {

		String id = request.getId();
		LOGGER.info("Date time by ID: {}", id);

		DateTimeResponse response = new DateTimeResponse();
		response.setId(id);
		response.setStart(new Date().toString());
		response.setEnd(dateTimeService.getDateTime());

		return response;
	}

}
